package com.kalvin.kvf.modules.dep.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.kalvin.kvf.common.controller.BaseController;
import com.kalvin.kvf.common.dto.R;
import com.kalvin.kvf.modules.dep.entity.Dps;
import com.kalvin.kvf.modules.dep.service.DpsService;

/**
 * <p>
 *  前端控制器
 * </p>
 * @since 2021-03-07 13:13:08
 */
@RestController
@RequestMapping("dep/dps")
public class DpsController extends BaseController {

    @Autowired
    private DpsService dpsService;

    @RequiresPermissions("dep:dps:index")
    @GetMapping("index")
    public ModelAndView index() {
        return new ModelAndView("dep/dps");
    }

    @GetMapping(value = "edit")
    public ModelAndView edit(Long id) {
        ModelAndView mv = new ModelAndView("dep/dps_edit");
        Dps dps;
        if (id == null) {
            dps = new Dps();
        } else {
            dps = dpsService.getById(id);
        }
        mv.addObject("editInfo", dps);
        return mv;
    }

    @GetMapping(value = "list/data")
    public R listData(Dps dps) {
        Page<Dps> page = dpsService.listDpsPage(dps);
        return R.ok(page);
    }

    @RequiresPermissions("dep:dps:add")
    @PostMapping(value = "add")
    public R add(Dps dps) {
        dps.setId(1l);
        dpsService.save(dps);
        return R.ok();
    }

    @RequiresPermissions("dep:dps:edit")
    @PostMapping(value = "edit")
    public R edit(Dps dps) {
        dpsService.updateById(dps);
        return R.ok();
    }

    @RequiresPermissions("dep:dps:del")
    @PostMapping(value = "del/{id}")
    public R del(@PathVariable Long id) {
        dpsService.removeById(id);
        return R.ok();
    }

    @GetMapping(value = "get/{id}")
    public R get(@PathVariable Long id) {
        return R.ok(dpsService.getById(id));
    }

}

